/**
 * 
 */
package com.jie.eclipse.pan.swtitem.table.cellmodifier;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.swt.widgets.TableItem;

import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.swtitem.table.PTableViewer;

/**
 * @author yanjie
 *
 */
public class BaseCellModifier implements ICellModifier{
	private PTableViewer tv = null;
	/**
	 * 
	 */
	public BaseCellModifier(PTableViewer tv) {
		this.tv = tv;
	}
	
	public boolean canModify(Object element, String property) {
		return false;
	}

	public Object getValue(Object element, String property) {
		if(element instanceof BaseDataEntity){
			return ((BaseDataEntity)element).gpsv(property);
		}
		return "";
	}
	
	public void modify(Object element, String property,Object value) {
		TableItem tableItem = (TableItem)element;
		if(tableItem == null)return;
		BaseDataEntity data = (BaseDataEntity)tableItem.getData();
		if(data == null)return;
		if(property.endsWith("_text") && value instanceof Object[]){
			Object[] item = (Object[])value;
			if(item.length ==2){
				data.spov(property, item[0]);
				data.spov(property.replace("_text", ""), item[1]);
			}
		}else{
			data.spov(property, value);
		}
		tv.update(data, null);
	}
	
	public PTableViewer getTableViewer(){
		return this.tv;
	}
}
